﻿<%@ WebHandler Language="VB" Class="Handler" %>

Imports System
Imports System.Web
Imports System.Data.SqlClient

Public Class Handler : Implements IHttpHandler
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("Management_Info_SysConnectionString").ConnectionString)
            Const SQL As String = "SELECT [img_id], [img], [img_desc],img_table FROM [img_items] WHERE [img_table] = @PictureID"
            Dim myCommand As New SqlCommand(SQL, myConnection)
            myCommand.Parameters.AddWithValue("@PictureID", context.Request.QueryString("PictureID"))

            myConnection.Open()
            Dim myReader As SqlDataReader = myCommand.ExecuteReader

            If myReader.Read Then
                context.Response.ContentType = myReader("img_desc").ToString()
                context.Response.BinaryWrite(myReader("img"))
            End If

            myReader.Close()
            myConnection.Close()
            
        End Using
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class